import {
  Controller,
  Get,
  Post,
  Body,
  Patch,
  Param,
  Delete,
  Query,
} from '@nestjs/common';
import { ArticleService } from './article.service';
import { CreateArticleDto } from './dto/create-article.dto';
import { UpdateArticleDto } from './dto/update-article.dto';
import {
  ApiTags,
  ApiOperation,
  ApiResponse,
  ApiParam,
  ApiQuery,
  ApiBody,
  ApiCreatedResponse,
  ApiOkResponse,
  ApiNotFoundResponse,
} from '@nestjs/swagger';
import { QueryArticleDto } from './dto/query-article.dto';
import { Public } from '../common/isPublic';
@ApiTags('文章')
@Public()
@Controller('article')
export class ArticleController {
  constructor(private readonly articleService: ArticleService) {}

  @Post()
  @ApiOperation({ summary: '创建文章' })
  @ApiBody({ type: CreateArticleDto })
  @ApiCreatedResponse({ description: '文章创建成功', type: CreateArticleDto })
  create(@Body() createArticleDto: CreateArticleDto) {
    return this.articleService.create(createArticleDto);
  }

  // article.controller.ts
  @Get()
  @ApiOperation({ summary: '获取所有文章' })
  @ApiQuery({ name: 'currentPage', type: Number, required: false })
  @ApiQuery({ name: 'pageSize', type: Number, required: false })
  @ApiQuery({ name: 'title', type: String, required: false })
  @ApiResponse({
    status: 200,
    description: '获取文章列表成功',
    type: [CreateArticleDto],
  })
  findAll(@Query() query: QueryArticleDto) {
    return this.articleService.findAll(query);
  }

  @Get(':id')
  @ApiOperation({ summary: '根据ID获取文章详情' })
  @ApiParam({ name: 'id', description: '文章ID' })
  @ApiOkResponse({ description: '获取文章详情成功', type: CreateArticleDto })
  @ApiNotFoundResponse({ description: '文章未找到' })
  findOne(@Param('id') id: string) {
    return this.articleService.findOne(id);
  }

  @Patch(':id')
  @ApiOperation({ summary: '更新文章' })
  @ApiParam({ name: 'id', description: '文章ID' })
  @ApiBody({ type: UpdateArticleDto })
  @ApiOkResponse({ description: '文章更新成功', type: UpdateArticleDto })
  update(@Param('id') id: string, @Body() updateArticleDto: UpdateArticleDto) {
    return this.articleService.update(id, updateArticleDto);
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除文章' })
  @ApiParam({ name: 'id', description: '文章ID' })
  @ApiOkResponse({ description: '文章删除成功' })
  @ApiNotFoundResponse({ description: '文章未找到' })
  remove(@Param('id') id: string) {
    return this.articleService.remove(id);
  }
}
